﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
 
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class Merging : DemoBaseUserControl
    {
        public Merging()
        {
            InitializeComponent();
            this.Title = "自动合并";
            this.Description = "Spread .NET  提供自动合并功能，根据你设置的表单内容自动合并相同内容的单元格。本示例中你可以通过选择按钮来展示不同合并方式。";
        }

        private void Merging_Load(object sender, System.EventArgs e)
        {
            LoadData();
        }
        public void LoadData()
        {
            FarPoint.Win.Spread.CellType.DateTimeCellType dtformat = new FarPoint.Win.Spread.CellType.DateTimeCellType();
            dtformat.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.TimeOnly;
            FpSpread1.Sheets[0].RowCount = 39;
            FpSpread1.Sheets[0].ColumnCount = 5;
            FpSpread1.Sheets[0].Columns[1].Width = 150;
            FpSpread1.Sheets[0].Columns[4].CellType = dtformat;
            FpSpread1.Sheets[0].AddColumns(1, 1);
            
            FpSpread1.Sheets[0].SetClip(0, 0, 1, 5, "皮特" + "\t" + "旧金山" + "\t" + "斯科特" + "\t" + "斯科特" + "\t" + "12:00");
            FpSpread1.Sheets[0].SetClip(1, 0, 1, 5, "皮特" + "\t" + "旧金山" + "\t" + "斯科特" + "\t" + "克莉丝" + "\t" + "12:00");
            FpSpread1.Sheets[0].SetClip(2, 0, 1, 5, "皮特" + "\t" + "旧金山" + "\t" + "斯科特" + "\t" + "克莉丝" + "\t" + "1:00");
            FpSpread1.Sheets[0].SetClip(3, 0, 1, 5, "朱莉" + "\t" + "旧金山" + "\t" + "斯科特" + "\t" + "斯科特" + "\t" + "12:00");
            FpSpread1.Sheets[0].SetClip(4, 0, 1, 5, "皮特" + "\t" + "奥兰多" + "\t" + "克里斯" + "\t" + "克莉丝" + "\t" + "1:00");
            FpSpread1.Sheets[0].SetClip(5, 0, 1, 5, "卡特" + "\t" + "奥兰多" + "\t" + "克里斯" + "\t" + "克莉丝" + "\t" + "2:00");
            FpSpread1.Sheets[0].SetClip(6, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格利特" + "\t" + "斯科特" + "\t" + "2:00");
            FpSpread1.Sheets[0].SetClip(7, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格利特" + "\t" + "吉姆" + "\t" + "2:00");
            FpSpread1.Sheets[0].SetClip(8, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格雷特" + "\t" + "吉姆" + "\t" + "3:00");
            FpSpread1.Sheets[0].SetClip(9, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "斯科特" + "\t" + "吉姆" + "\t" + "4:00");
            FpSpread1.Sheets[0].SetClip(10, 0, 1, 5, "雷恩" + "\t" + "罗利" + "\t" + "斯科特" + "\t" + "斯科特" + "\t" + "7:00");
            FpSpread1.Sheets[0].SetClip(11, 0, 1, 5, "雷恩" + "\t" + "卡里" + "\t" + "詹尼" + "\t" + "赖安" + "\t" + "6:00");
            FpSpread1.Sheets[0].SetClip(12, 0, 1, 5, "皮特" + "\t" + "旧金山" + "\t" + "斯科特" + "\t" + "斯科特" + "\t" + "12:00");
            FpSpread1.Sheets[0].SetClip(13, 0, 1, 5, "皮特" + "\t" + "旧金山" + "\t" + "斯科特" + "\t" + "克莉丝" + "\t" + "12:00");
            FpSpread1.Sheets[0].SetClip(14, 0, 1, 5, "皮特" + "\t" + "旧金山" + "\t" + "斯科特" + "\t" + "克莉丝" + "\t" + "1:00");
            FpSpread1.Sheets[0].SetClip(15, 0, 1, 5, "朱莉" + "\t" + "旧金山" + "\t" + "斯科特" + "\t" + "斯科特" + "\t" + "12:00");
            FpSpread1.Sheets[0].SetClip(16, 0, 1, 5, "皮特" + "\t" + "奥兰多" + "\t" + "克里斯" + "\t" + "克莉丝" + "\t" + "1:00");
            FpSpread1.Sheets[0].SetClip(17, 0, 1, 5, "卡特" + "\t" + "奥兰多" + "\t" + "克里斯" + "\t" + "克莉丝" + "\t" + "2:00");
            FpSpread1.Sheets[0].SetClip(18, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格利特" + "\t" + "斯科特" + "\t" + "2:00");
            FpSpread1.Sheets[0].SetClip(19, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格利特" + "\t" + "吉姆" + "\t" + "2:00");
            FpSpread1.Sheets[0].SetClip(20, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格雷特" + "\t" + "吉姆" + "\t" + "3:00");
            FpSpread1.Sheets[0].SetClip(21, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "斯科特" + "\t" + "吉姆" + "\t" + "4:00");
            FpSpread1.Sheets[0].SetClip(22, 0, 1, 5, "雷恩" + "\t" + "罗利" + "\t" + "斯科特" + "\t" + "斯科特" + "\t" + "7:00");
            FpSpread1.Sheets[0].SetClip(23, 0, 1, 5, "雷恩" + "\t" + "卡里" + "\t" + "詹尼" + "\t" + "赖安" + "\t" + "6:00");
            FpSpread1.Sheets[0].SetClip(20, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格雷特" + "\t" + "吉姆" + "\t" + "3:00");
            FpSpread1.Sheets[0].SetClip(21, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "斯科特" + "\t" + "吉姆" + "\t" + "4:00");
            FpSpread1.Sheets[0].SetClip(22, 0, 1, 5, "雷恩" + "\t" + "罗利" + "\t" + "斯科特" + "\t" + "斯科特" + "\t" + "7:00");
            FpSpread1.Sheets[0].SetClip(23, 0, 1, 5, "雷恩" + "\t" + "卡里" + "\t" + "詹尼" + "\t" + "赖安" + "\t" + "6:00");
            FpSpread1.Sheets[0].SetClip(24, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格雷特" + "\t" + "吉姆" + "\t" + "3:00");
            FpSpread1.Sheets[0].SetClip(25, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "斯科特" + "\t" + "吉姆" + "\t" + "4:00");
            FpSpread1.Sheets[0].SetClip(26, 0, 1, 5, "雷恩" + "\t" + "罗利" + "\t" + "斯科特" + "\t" + "斯科特" + "\t" + "7:00");
            FpSpread1.Sheets[0].SetClip(27, 0, 1, 5, "雷恩" + "\t" + "卡里" + "\t" + "詹尼" + "\t" + "赖安" + "\t" + "6:00");
            FpSpread1.Sheets[0].SetClip(28, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格雷特" + "\t" + "吉姆" + "\t" + "3:00");
            FpSpread1.Sheets[0].SetClip(29, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "斯科特" + "\t" + "吉姆" + "\t" + "4:00");
            FpSpread1.Sheets[0].SetClip(30, 0, 1, 5, "雷恩" + "\t" + "罗利" + "\t" + "斯科特" + "\t" + "斯科特" + "\t" + "7:00");
            FpSpread1.Sheets[0].SetClip(31, 0, 1, 5, "雷恩" + "\t" + "卡里" + "\t" + "詹尼" + "\t" + "赖安" + "\t" + "6:00");
            FpSpread1.Sheets[0].SetClip(32, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格雷特" + "\t" + "吉姆" + "\t" + "3:00");
            FpSpread1.Sheets[0].SetClip(33, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "斯科特" + "\t" + "吉姆" + "\t" + "4:00");
            FpSpread1.Sheets[0].SetClip(34, 0, 1, 5, "雷恩" + "\t" + "罗利" + "\t" + "斯科特" + "\t" + "斯科特" + "\t" + "7:00");
            FpSpread1.Sheets[0].SetClip(35, 0, 1, 5, "雷恩" + "\t" + "卡里" + "\t" + "詹尼" + "\t" + "赖安" + "\t" + "6:00");
            FpSpread1.Sheets[0].SetClip(36, 0, 1, 5, "皮特" + "\t" + "纽约" + "\t" + "格雷特" + "\t" + "吉姆" + "\t" + "3:00");
            FpSpread1.Sheets[0].AddColumns(3, 1);
            for (int i = 0; i < FpSpread1_Sheet1.RowCount; i++)
            {
                FpSpread1.Sheets[0].Cells[i, 3].Value = "斯科特"; 
            }
            FpSpread1.Sheets[0].AddColumns(2, 1);
            for (int j = 0; j < FpSpread1_Sheet1.RowCount; j++)
            {
                if (j < 16)
                {
                    FpSpread1.Sheets[0].Cells[j, 2].Value = "旧金山";
                }
                else
                {
                    FpSpread1.Sheets[0].Cells[j, 2].Value = "纽约";
                }
            }
            FpSpread1.Sheets[0].AddColumns(2, 1);
            for (int j = 0; j < FpSpread1_Sheet1.RowCount; j++)
            {
                if (j < 16)
                {
                    FpSpread1.Sheets[0].Cells[j, 2].Value = "旧金山";
                }
                else
                {
                    FpSpread1.Sheets[0].Cells[j, 2].Value = "纽约";
                }
            }
            FpSpread1.Sheets[0].AddColumns(2, 1);
            for (int k = 0; k < FpSpread1_Sheet1.RowCount; k++)
            {
                if (k < 16)
                {
                    FpSpread1.Sheets[0].Cells[k, 2].Value = "旧金山";
                }
                else
                {
                    FpSpread1.Sheets[0].Cells[k, 2].Value = "纽约";
                }
            }

            
            FpSpread1.Sheets[0].SetColumnMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always);
            FpSpread1.Sheets[0].SetRowMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.None);
            this.radioButton3.Checked = true;
        }

        private void radioButton1_Click(object sender, System.EventArgs e)
        {
            FpSpread1.Sheets[0].SetColumnMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.None);
            FpSpread1.Sheets[0].SetRowMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.None);
            FpSpread1.SetBounds(FpSpread1.Bounds.X, FpSpread1.Bounds.Y, FpSpread1.Bounds.Width + 1, FpSpread1.Bounds.Height);
        }

        private void radioButton2_Click(object sender, System.EventArgs e)
        {
            FpSpread1.Sheets[0].SetColumnMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.None);
            FpSpread1.Sheets[0].SetRowMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always);
            FpSpread1.SetBounds(FpSpread1.Bounds.X, FpSpread1.Bounds.Y, FpSpread1.Bounds.Width + 1, FpSpread1.Bounds.Height);
        }

        private void radioButton3_Click(object sender, System.EventArgs e)
        {
            FpSpread1.Sheets[0].SetRowMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.None);
            FpSpread1.Sheets[0].SetColumnMerge(-1, FarPoint.Win.Spread.Model.MergePolicy.Always);
            FpSpread1.SetBounds(FpSpread1.Bounds.X, FpSpread1.Bounds.Y, FpSpread1.Bounds.Width + 1, FpSpread1.Bounds.Height);
        }
    }
}
